/**
 * Created by Administrator on 2016/7/13.
 */
var u_id = sessionStorage.u_id;
var user_token = sessionStorage.user_token;
var session_id = sessionStorage.session_id;

$(document).ready(function(){
    var $width = $(window).width();
    var $height = $(window).height();
    $(".mask").css({'height':$height+200,'width':$width});
    //获取订单编号
    var str = window.location.search;
    var orderNumber = str.replace(/[^0-9]+/g, '');
    var minute = sessionStorage.minute;
    //调用订单详情接口
    var check_type = "1";
    $.ajaxSettings.async=false;
    $.post(commonval+"/orderInfo",{
        user_token:user_token,
        device:"wap",
        order_num:orderNumber,
        check_type:check_type,
        session_id:session_id
    },function(data){
        if(data.status == 1){
            var name =  data.data.name;
            var user_tel = data.data.user_tel;
            var doctor_tel = data.data.doctor_tel;
            var order_num = data.data.order_num;
            $("button:nth-child(3)").click(function(){
                $.ajaxSettings.async = false;
                $.post(commonval+"/callBack", {
                    user_token:user_token,
                    device:"wap",
                    order_num: order_num,
                    from: user_tel,
                    to: doctor_tel,
                    session_id:session_id
                }, function (data) {
                    if(data.status == 1){
                        if(data.data.type == 3){
                            createWindow1("帮您呼叫中……");
                            function createWindow1(msg) {
                                $(".mask").click(function(){
                                    $(".mask").css({'display':'none'});
                                    $('.showMsg1').remove();
                                })
                                $('.mask').css({'display':'block'});
                                var window =$("<section class='showMsg1'></section>");
                                var img = "<img src='../images/callBeing.gif'>";
                                var show = "<p>"+msg+"</p>";
                                window.append(img);
                                window.append(show);
                                $("body").append(window);
                                setTimeout("$('.showMsg1').remove()",5000);
                                setTimeout("$('.mask').css({'display':'none'})",5000);
                                setTimeout(function(){location.href = "consult.html";},5000);
                            }
                        }else{
                            createWindow1("由于网络问题，联系失败,请稍后重试。");
                            function createWindow1(msg) {
                                $(".mask").click(function(){
                                    $(".mask").css({'display':'none'});
                                    $('.showMsg1').remove();
                                })
                                $('.mask').css({'display':'block'});
                                var window =$("<section class='showMsg1'></section>");
                                var img = "<img src='../images/webFailed.png'>";
                                var show = "<p>"+msg+"</p>";
                                window.append(img);
                                window.append(show);
                                $("body").append(window);
                                setTimeout("$('.showMsg1').remove()",5000);
                                setTimeout("$('.mask').css({'display':'none'})",5000);
                            }

                        }
                    }else{
                        createWindow1("由于网络问题，联系失败,请稍后重试。");
                        function createWindow1(msg) {
                            $(".mask").click(function(){
                                $(".mask").css({'display':'none'});
                                $('.showMsg1').remove();
                            })
                            $('.mask').css({'display':'block'});
                            var window =$("<section class='showMsg1'></section>");
                            var img = "<img src='../images/webFailed.png'>";
                            var show = "<p>"+msg+"</p>";
                            window.append(img);
                            window.append(show);
                            $("body").append(window);
                            setTimeout("$('.showMsg1').remove()",5000);
                            setTimeout("$('.mask').css({'display':'none'})",5000);
                        }
                    }
                })
            })
            $("button:nth-child(4)").click(function(){
                location.href = "consult.html";
            })
            $("section p span:first-child").text(name);
            $("section p span:first-child").css("color","#FE3000");
            $("section p span:nth-child(2)").text(minute+"分钟");
        }else{
            createWindow("网络故障");
            function createWindow(msg) {
                var window =$("<section class='showMsg'></section>");
                var show = "<p>"+msg+"</p>";
                window.append(show);
                $("body").append(window);
                setTimeout("$('.showMsg').remove()",3000);
            }
        }
    });
})
